import { InitModalMethod, ParseModalMethod } from './defination';

/**
 * 设置表单属性
 * @param { Object } form 表单数据
 * @param { Object } workstep cached的ai工作流
 */
export const initModalData = (form = {}, workstep = {}) => {
	if (!form || !workstep || !workstep.after || !workstep.summary) {
		return;
	}

	const clone = JSON.parse(JSON.stringify(workstep));
	// summary
	form.summary = clone.summary;

	// yes
	form.nextStepYes = workstep.after?.id;

	// notifyExternal
	form.notifyExternal = clone.notifyExternal;

	form.informationRushurlAddress = clone.notifyExternal.url ? clone.notifyExternal.url : '';

	form.wordsVariable = clone.notifyExternal.params ? clone.notifyExternal.params : [];
	form.name = workstep.name;
};
InitModalMethod['messageSummary'] = initModalData;

/**
 * 解析表单属性
 * @param { Object } form 表单数据
 * @param { Object } workstep cached的ai工作流
 */
export const parseModalData = (form = {}, workstep = {}) => {
	console.log('##???message summary', form, workstep);
	if (!form || !workstep || !workstep.do || !workstep.summary) {
		return;
	}

	const clone = JSON.parse(JSON.stringify(form));

	// summary
	workstep.summary = clone.summary;

	// yes
	workstep.after.id = form.nextStepYes;

	// notifyExternal
	workstep.notifyExternal = clone.notifyExternal;
	workstep.notifyExternal.url = clone.informationRushurlAddress ? clone.informationRushurlAddress : '';
	workstep.notifyExternal.params = clone.wordsVariable ? clone.wordsVariable : [];

	workstep.name = form.name;
};
ParseModalMethod['messageSummary'] = parseModalData;
// {
//     "robotProperty": {
//         "needHearing": "preorder",
//         "videoType": "preorder",
//         "audioType": "preorder"
//     },
//     "no": "messageSummary_4",
//     "id": "messageSummary_4",
//     "type": "messageSummary",
//     "summary": [
//         {
//             "node": "messageCollect_1",
//             "name": "信息记录 1"
//         }
//     ],
//     "do": {
//         "command": "storageMessageSummary"
//     },
//     "after": {
//         "command": "jump-to",
//         "no": "BlankNode_5",
//         "id": "BlankNode_5",
//         "type": "yes"
//     },
//     "notifyExternal": {
//         "url": "https://www.baidu.com",
//         "method": "post",
//         "params": [
//             {
//                 "describe": "年龄",
//                 "initMode": "user-data",
//                 "name": "age",
//                 "id": 305,
//                 "type": "numeric",
//                 "isInvalid": false
//             }
//         ]
//     },
//     "completed": true,
//     "hasStartNode": true
// }
